<?php

namespace app\common\service;

class DoubleLayeredPdfService
{

    /**
     * 合成双层pdf
     * @param $jsonData  json数据定位位置
     * @param $pdfPath 单层pdf路径
     * @param $doubleLayeredPdfPath  输出双层pdf路径
     */

    public function index($jsonData, $pdfPath , $doubleLayeredPdfPath)
    {
        $ch = curl_init();
        $url = config("pdfServerdoub") . "/api/image_to_ocr";   
       
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 返回结果而不是直接输出
        curl_setopt($ch, CURLOPT_POST, 1); // 设置为POST请求
        $postData = '{
            "file_path":"' . $jsonData . '",
            "pdf_path":"' . $pdfPath . '",
            "output_pdf_path_Out":"' . $doubleLayeredPdfPath . '"
        }';
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
// 设置请求头
        $headers = array();
        $headers[] = 'Accept: application/json, text/plain, */*';
        $headers[] = 'Accept-Language: zh-CN,zh;q=0.9';
        $headers[] = 'Connection: keep-alive';
        $headers[] = 'Content-Type: application/json';
        $headers[] = 'Cookie: x-hng=lang=zh-CN; ctoken=bigfish_ctoken_19e887cg4a';
        $headers[] = 'Origin: http://192.168.2.108:8887';
        $headers[] = 'Referer: http://192.168.2.108:8887/';
        $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $response = curl_exec($ch);
        curl_close($ch);
// 关闭 cURL 会话
//        curl_close($ch);
        $arr = json_decode($response, true);
        var_dump($arr);
       

        return $arr;
    
    }
    
}